<template>
    <el-container>
        <!-- 头部区域 -->
        <el-header>
            <div>
                <img src="../assets/img/heima.png" alt="公司logo">
                <span>电商后台管理系统</span>
            </div>
            <el-button @click=logout>退出登录</el-button>
        </el-header>
        <!-- 头部区域0 -->

        <el-container>

            <!-- 侧边区域 -->
            <el-aside :width='isCollapse?"64px":"200px"'>
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu background-color="#333743" text-color="#fff" active-text-color="rgb(87, 88, 195)" unique-opened :collapse = 'isCollapse' :collapse-transition='false' router>
                    <el-submenu v-for="(value,key) in menuData" :key="key" :index="value.id+''">    
                        <!-- 一级菜单 -->
                        <template slot="title">
                            <i :class="iconData[value.id]"></i>
                            <span>{{value.authName}}</span>
                        </template>
                        <!-- 二级菜单 -->
                        <el-menu-item v-for="(value2,key2) in value.children" :key="key2" :index="'/'+value2.path">
                            <i class="el-icon-menu"></i>
                            <span>{{value2.authName}}</span>
                        </el-menu-item>

                    </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 侧边区域0 -->
            
            <!-- 主题区域 -->
            <el-main>
                <router-view></router-view>
            </el-main>
            <!-- 主题区域0 -->

        </el-container>
    </el-container>
</template>
<style lang = less scoped>
.toggle-button{
    height: 30px;
    font-size: 9px;
    color: #fff;
    letter-spacing: 5px;
    text-align: center;
    line-height: 30px;
    cursor:pointer;
}
.toggle-button:hover{
    background-color:#42454e;
}
.el-menu{
    border:none;
}
.el-container{
    height: 100%;
}
.el-aside,.el-header{
    background-color: #333743;
}
.el-header{
    padding-left: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    > div{
        display: flex;
        align-items: center;
        span{
            margin-left: 20px;
            font-size: 20px;
            color:#fff
        }
    }
}
.el-main{
    background-color: #e9edf0;
}
.el-submenu{
    background-color: #333743;
}
.iconfont{
    margin-right:10px;
}
</style>
<script>
export default{
    data(){
        return{
            menuData:[],
            iconData:{
                '125':'iconfont icon-user',
                '103':'iconfont icon-tijikongjian',
                '101':'iconfont icon-shangpin',
                '102':'iconfont icon-danju',
                '145':'iconfont icon-danju',
            },
            isCollapse:false
        }
    },
    created(){
        this.getMenuList()
    },
    methods:{
        logout(){
            window.sessionStorage.clear()
            this.$router.push('/login')
        },
        async getMenuList(){
            var {data:response}= await this.$http.get('/menus');
            if (response.meta.status!=200) return this.$message.error(response.meta.msg)
            this.menuData=response.data;
        },
        toggleCollapse(){
            this.isCollapse= ! this.isCollapse;
        }
    }
}
</script>